#ifndef LRU_H
#define LRU_H


#include <string>
#include <list>
#include <unordered_map>
#include <vector>
#include <mutex>
#include <thread>
#include <memory>
#include <thread>
#include <cmath>

using std::thread;
using std::pair;
using std::string;
using std::unordered_map;   
using std::vector;
using std::list;
using std::mutex;
using std::shared_ptr;





class KeyWordLRUCache {
public:
   static KeyWordLRUCache& getInstance(int capacity=200) {
        static KeyWordLRUCache instance(capacity);
        return instance;
    }

public:
    struct CacheNode {
        string m_key;
        string m_values;
    };

public: 
    // 获取缓存中的值
    string get(string key);
    // 插入缓存
    void put(string key, string values);
    
    KeyWordLRUCache& operator=(const KeyWordLRUCache&) = delete;
    KeyWordLRUCache(const KeyWordLRUCache&) = delete;

private:
    KeyWordLRUCache(int capacity=200);
    ~KeyWordLRUCache();
    mutex _mutex;
    int _capacity;
    // std::shared_ptr<list<CacheNode>> _cache;
    // std::shared_ptr<unordered_map<string, list<CacheNode>::iterator>> _index;
    vector<std::pair<std::shared_ptr<list<CacheNode>>, std::shared_ptr<unordered_map<string, list<CacheNode>::iterator>>>> _cachesum;
};


#endif